#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <gmp.h>
#include <gmp-x86_64.h>
#include <string.h>
#define SEED 35791246

main(int argc, char* argv)
{
   int niter = 1, count = 0;
   
   mpf_t x, y, z, pi;
   mp_bitcnt_t prec;
   mp_bitcnt_t maxPrec = 130;
   
   mpf_init2(x,10);      
   mpf_init2(y,10);
   mpf_init2(z,10);
   
   mpf_init2(pi,100);
   prec = 100;
   
   /* initialize random numbers */
   srand(SEED);
   
   while( prec < maxPrec){
      mpf_set_d( x ,(double)rand()/RAND_MAX);
      mpf_set_d( y ,(double)rand()/RAND_MAX);
      mpf_mul(x,x,x);
      mpf_mul(y,y,y);
      mpf_add(z,x,y);
      
      if (mpf_cmp_d(z,(double)1) < 0) 
          count++;
      
      mpf_set_d( pi ,(double)count/niter*4);
      niter++;
      
      prec = mpf_get_prec(pi);

      mpf_out_str(stdout,10,0,pi);
      printf("\n");
   }
   
   return 0;
}
